<template>
  <div v-if="value" class="v-game-loading">
    <!-- -->
    {{ countdownNumber }}
  </div>
</template>

<script>
export default {
  name: 'VGameLoading',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    time: {
      type: Number,
      default: 3
    }
  },
  data() {
    return {
      countdownNumber: this.time
    };
  },
  created() {
  },
  mounted() {
    this.timer = setInterval(() => {
      this.startLoading()
    }, 1000)
    // this.startLoading()
  },

  methods: {
    startLoading() {
      if(this.countdownNumber >= 0) {
        this.countdownNumber--
      }
      if(this.countdownNumber <= 0) {
        this.$emit('overLoading')
        clearInterval(this.timer)
        this.countdownNumber = 3
      }
    }
  },
};
</script>

<style lang="scss">
.v-game-loading {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: rgb(255, 84, 84, .6);
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 5rem;
  color: #fff;
}
</style>